package kg.aibek.poker;

public class Card implements Comparable<Card> {
	private int value;
	private String suit;

	public Card(String str) {
		if (str.length() != 2) {
			return;
		}

		String v = str.charAt(0) + "";
		if (v.equals("T")) {
			value = 10;
		} else if (v.equals("J")) {
			value = 11;
		} else if (v.equals("Q")) {
			value = 12;
		} else if (v.equals("K")) {
			value = 13;
		} else if (v.equals("A")) {
			value = 14;
		} else {
			value = Integer.parseInt(v);
		}

		suit = str.charAt(1) + "";
	}

	public Card(String suit, int value) {
		this.value = value;
		this.suit = suit;
	}

	public int getValue() {
		return value;
	}

	public void setValue(int value) {
		this.value = value;
	}

	public String getSuit() {
		return suit;
	}

	public void setSuit(String suit) {
		this.suit = suit;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((suit == null) ? 0 : suit.hashCode());
		result = prime * result + value;
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Card other = (Card) obj;
		if (suit == null) {
			if (other.suit != null)
				return false;
		} else if (!suit.equals(other.suit))
			return false;
		if (value != other.value)
			return false;
		return true;
	}

	@Override
	public int compareTo(Card o) {
		if (this.value > o.value)
			return 1;

		if (this.value < o.value)
			return -1;

		return 0;

	}

}
